﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data.SqlClient;
using System.Data;
using TimKen.DataEntity;

namespace TimKen.DataAccess
{
    /// <summary>
    /// 数据访问类PDiffPrice。
    /// </summary>
    public class PDiffPriceDAO
    {
        public PDiffPriceDAO()
        { }
        #region  成员方法
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PDiffPrice GetModel(string ItemCode, decimal Qty)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@ItemCode", SqlDbType.NChar,10),
					new SqlParameter("@Qty", SqlDbType.Float)};
            parameters[0].Value = ItemCode;
            parameters[1].Value = Qty;

            PDiffPrice model = new PDiffPrice();
            DataSet ds = DbHelperSQL.RunProcedure("UP_PDiffPrice_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ItemCode = ds.Tables[0].Rows[0]["ItemCode"].ToString();
                if (ds.Tables[0].Rows[0]["Qty"].ToString() != "")
                {
                    model.Qty = decimal.Parse(ds.Tables[0].Rows[0]["Qty"].ToString());
                }
                model.Type = ds.Tables[0].Rows[0]["Type"].ToString();
                if (ds.Tables[0].Rows[0]["Discount"].ToString() != "")
                {
                    model.Discount = decimal.Parse(ds.Tables[0].Rows[0]["Discount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public IList<PDiffPrice> GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ItemCode,Qty,Type,Discount,Price ");
            strSql.Append(" FROM PDiffPrice ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            IList<PDiffPrice> list = new List<PDiffPrice>();
            foreach (DataRow dr in DbHelperSQL.Query(strSql.ToString()).Tables[0].Rows)
            {
                PDiffPrice pdp = new PDiffPrice();
                if (dr["Discount"] != null)
                {
                    pdp.Discount = Convert.ToDecimal(dr["Discount"]);
                }
                if (dr["ItemCode"] != null)
                {
                    pdp.ItemCode = dr["ItemCode"].ToString();
                } if (dr["Price"] != null)
                {
                    pdp.Price = Convert.ToDecimal(dr["Price"]);
                } if (dr["Qty"] != null)
                {
                    pdp.Qty = Convert.ToDecimal(dr["Qty"]);
                } if (dr["Type"] != null)
                {
                    pdp.Type = dr["Type"].ToString();
                }
                list.Add(pdp);
            }
            return list;
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "PDiffPrice";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}
